<?php
	require_once('../../Construct/Zeal_Construct.php');
	function echoline($str)
	{
		echo($str . "<br />\n");
	}
class Pattern_Entry extends Zeal_Object_Construct
{
	private $_name_ = '';

	function __construct($name)
	{
		parent::__construct();
		$this->Name = $name;
	}

	function defSize()
	{
		return 0;
	}

	public function add(Pattern_Entry $entry)
	{
		throw new Exception();
	}

	public function printList($prefix)
	{

	}

}

class Pattern_File extends Pattern_Entry {
	private $_size_;

	function __construct($name, $size)
	{
		parent::__construct($name);
		$this->Size = $size;
	}

	public function printList($prefix) {
		$str = sprintf("%s/%s (%s)",
			$prefix,
			$this->Name,
			$this->Size
		);
		echoline($str);
	}
} //class end

class Pattern_Directory extends Pattern_Entry {
	public $_Directory_ = array();

	public function __construct($name)
	{
		parent::__construct($name);
	}

	public function getSize()
	{
		$size = 0;
		foreach ($this->Directory as $entry){
			$size += $entry->Size;
		}

		return $size;
	}

	function defDirectory()
	{
		return array();
	}

	public function add($entry)
	{
		$this->Directory[] = $entry;
	
		return $this;
	}

	function &getDirectory()
	{
		return $this->_Directory_; 
	}

	public function printList($prefix='')
	{
		$str = sprintf("%s/%s (%s)",
			$prefix,
			$this->Name,
			$this->Size
		);

		echoline($str);
		foreach ($this->Directory as $entry) {
			$entry->printList($prefix . "/" . $this->Name);
		}
	}
} //class end

class Pattern_Program
{
	public function main($args=array())
	{
		$windows = new Pattern_Directory("Windows");
		$system32 = new Pattern_Directory("system32");
		$windows->add($system32);
		$windows->add(new Pattern_File("desktop.ini", 923));
		$windows->add(new Pattern_File("TASKMAN.EXE", 15360));
		$system32->add(new Pattern_File("shutdown.exe", 23552));

		$windows->printList();
	}
}//class end

Pattern_Program::main();
?>
